package org.koyi.jsonUtil;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;

public class JsonAssets {
	
	private static final String NOMBRE_JSON = "datos.json";
	Context context = null;
	
	public JsonAssets(Context context) {
		this.context = context;
	}
	
	public JSONObject getJson()
	{
		JSONObject jsonObject = null;
		String json = null;
		
		try {
			
			InputStream inputStream = context.getAssets().open(NOMBRE_JSON);
			
			BufferedReader reader = new BufferedReader(new InputStreamReader(
                    inputStream, "UTF-8"), 8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            inputStream.close();
            json = sb.toString();
			
            jsonObject = new JSONObject(json);
            
		} 
        catch (IOException e) 
		{
			e.printStackTrace();
		} 
        catch (JSONException e) 
        {
			e.printStackTrace();
		}
		return jsonObject;
	}
}
